﻿<div class="layui-form-item">
    <div class="layui-inline">
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" id="Code" placeholder="租赁公司" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" id="Code" placeholder="园区名称" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" id="Code" placeholder="仓库编号" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" id="Code" placeholder="库位编号" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" id="Code" placeholder="起始日期" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" id="Code" placeholder="截止日期" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width:120px;">
            <input type="text" id="Code" placeholder="租赁费用" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <a class="layui-btn" id="btnSearch">搜索</a>
    </div>
</div>
<table id="table" class="layui-table" lay-filter="table"></table>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        @*@Html.LayuiButton("position", "三维定位", "layui-btn layui-btn-sm", "/Resource/Rent/Index")
        @Html.LayuiButton("imageShow", "图片查看", "layui-btn layui-btn-sm", "/Resource/Location/ImageShow")*@
        @Html.LayuiButton("add", "租赁登记", "layui-btn layui-btn-sm", "/Resource/Rent/Add")
        @Html.LayuiButton("edit", "编辑租赁", "layui-btn layui-btn-sm", "/Resource/Rent/Edit")
        @Html.LayuiButton("close", "结束租赁", "layui-btn layui-btn-sm", "/Resource/Rent/Close")
    </div>
</script>
<script>
    layui.use(['table', 'layer', 'form'], function () {
        var $ = layui.jquery;
        var table = layui.table;
        var layer = layui.layer;
        var form = layui.form;
        //查询
        function getWhere() {
            var where = { Code: $("#Code").val() };
            return where;
        }
        layui.tableReload = function () {
            table.reload("table", {
                where: getWhere(),
                page: { curr: 1 }
            });
        }
        $("#btnSearch").click(function () {
            layui.tableReload();
        })
        // 渲染表格
        table.render({
            id: "table",
            elem: '#table',
            method: "post",
            url: 'Index2',
            cellMinWidth: 80,
            toolbar: "#toolbar",
            cols: [
                [
                    { type: 'checkbox' },
                    { field: 'DeptName', title: '租赁公司' },
                    { field: 'ParkCode', title: '园区名称' },
                    { field: 'StorehouseCode', title: '仓库编号' },
                    { field: 'LocationCode', title: '库位编号' },
                    {
                        field: 'BeginDate', title: '起始日期', templet: function (d) {
                            return d.BeginDate == null ? "" : d.BeginDate.substring(0, 10);
                        }
                    },
                    {
                        field: 'EndDate', title: '截止日期', templet: function (d) {
                            return d.EndDate == null ? "" : d.EndDate.substring(0, 10);
                        }
                    },
                    { field: 'RentMoney', title: '租赁费用' },
                    { field: 'OtherMoney', title: '其他费用' },
                    { field: 'AmountMoney', title: '总费用' },
                    { field: 'CreateDate', title: '创建日期' },
                ]
            ],
            done: function (res, curr, count) { //res 即为原始返回的数据
                //console.log(res);
            },
            loading: true,
            event: true,
            page: { limit: 20 }
        });

        //监听头部事件
        table.on('toolbar(table)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id)
                , data = checkStatus.data; //获取选中的数据
            if (obj.event != "add") {
                if (data.length === 0) {
                    layer.msg('请选择一行');
                    return;
                } else if (data.length > 1) {
                    layer.msg('只能同时操作一个');
                    return;
                }
            }
            switch (obj.event) {
                case 'add':
                    //if (data[0].IsRented) {
                    //    layer.msg('所选库位已租赁');
                    //}
                    //else {
                    //    layer.open({
                    //        type: 2,
                    //        title: '新增租赁',
                    //        maxmin: true,
                    //        area: ['350px', '400px'],
                    //        content: 'Add?id=' + data[0].ID,
                    //        end: function () {
                    //            layui.tableReload();
                    //        }
                    //    });
                    //}
                    layer.open({
                        type: 2,
                        title: '租赁登记',
                        maxmin: true,
                        area: ['350px', '525px'],
                        content: 'RentAdd2',
                        end: function () {
                            layui.tableReload();
                        }
                    });
                    break;
                case 'edit':
                    //if (!data[0].IsRented) {
                    //    layer.msg('所选库位未租赁');
                    //}
                    //else {
                    //    layer.open({
                    //        type: 2,
                    //        title: '编辑租赁',
                    //        maxmin: true,
                    //        area: ['350px', '400px'],
                    //        content: 'Edit?id=' + data[0].ID,
                    //        end: function () {
                    //            layui.tableReload();
                    //        }
                    //    });
                    //}
                    layer.open({
                        type: 2,
                        title: '租赁编辑',
                        maxmin: true,
                        area: ['350px', '525px'],
                        content: 'RentAdd2',
                        end: function () {
                            layui.tableReload();
                        }
                    });
                    break;
                case 'close':
                    //if (!data[0].IsRented) {
                    //    layer.msg('所选库位未租赁');
                    //}
                    //else {
                    //    layer.open({
                    //        type: 2,
                    //        title: '结束租赁',
                    //        maxmin: true,
                    //        area: ['350px', '450px'],
                    //        content: 'Close?id=' + data[0].ID,
                    //        end: function () {
                    //            layui.tableReload();
                    //        }
                    //    });
                    //}
                    break;
                case 'position':
                    layer.open({
                        type: 2,
                        title: '三维定位',
                        maxmin: false,
                        area: ['100%', '100%'],
                        content: '/Resource/Show3D/ShowPosition?ParkID=' + data[0].ParkID + "&Code=" + data[0].Code
                    });
                    break;
                case 'imageShow':
                    $.ajax({
                        url: '/Resource/Location/ImageShow',
                        data: { id: data[0].ID },
                        success: function (res) {
                            if (res.count > 0) {
                                layer.photos({
                                    photos: res.data
                                    , anim: 5
                                });
                            }
                            else {
                                layer.msg(res.msg);
                            }
                        }
                    });
                    break;
                case 'rentCancel':
                    if (data[0].IsRented) {
                        $.ajax({
                            url: 'RentCancel',
                            data: { id: data[0].ID },
                            success: function (res) {
                                layer.alert(res.msg, function (index) {
                                    layer.close(index);
                                    if (res.count > 0) {
                                        layui.tableReload();
                                    }
                                })
                            }
                        });
                    }
                    else {
                        layer.msg('所选库位未租赁');
                    }
                    break;
            };
        });
    });
</script>